/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wisp.dataObjects;
import java.sql.*;
import java.io.*;
import java.util.*;
import java.util.Vector;
import java.lang.Exception.*;

/**
 *
 * @author nezie
 */
public class CurseLog {
  
    private String cmessage;
    private int cid, csequence;
    private dbConnection dbcon = new dbConnection();

    public String getCmessage() {
        return cmessage;
    }

    public void setCmessage(String cmessage) {
        this.cmessage = cmessage;
    }

    public int getCid() {
        return cid;
    }

    public void setCid(int cid) {
        this.cid = cid;
    }

    public int getCsequence() {
        return csequence;
    }

    public void setCsequence(int csequence) {
        this.csequence = csequence;
    }
//    public void addCurseLog (String msg, int i, int s){
//      						
//        String query; 					
//        PreparedStatement stmt;
//
//            getDbcon().connect();
//            query = "INSERT INTO CurseLog (cmessage, cid, csequence) VALUES (?,?,?)";
//            try 
//            {
//                stmt = getDbcon().con.prepareStatement(query);
//                stmt.setString(1, msg);
//                stmt.setInt(2, i);
//                stmt.setInt(3, s);
//                stmt.executeUpdate();	
//                stmt.close();
//            } catch (Exception ex) 
//            {
//                System.out.println(ex.getMessage());
//            }
//            getDbcon().disconnect();               
//        
//    }
   public void addCurseLog (CurseLog c){
      						
        String query; 					
        PreparedStatement stmt;
       
            getDbcon().connect();
            query = "INSERT INTO CurseLog (cmessage, cid, csequence) VALUES (?,?,?)";
            try 
            {
                stmt = getDbcon().con.prepareStatement(query);
                System.out.println("ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"+c.cmessage+" "+c.cid+" "+c.csequence);
                stmt.setString(1, c.cmessage);
                stmt.setInt(2, c.cid);
                stmt.setInt(3, c.csequence);
                stmt.executeUpdate();	
                stmt.close();
            } catch (Exception ex) 
            {
                System.out.println(ex.getMessage());
            }
            getDbcon().disconnect();               
        
    }
   
    public void addCurseLog1 (int id, Vector<String> slist){
      						
        String query; 					
        
       
            getDbcon().connect();
            for (int i = 0; i<slist.size();i++)
            {
            query = "INSERT INTO CurseLog ( cmessage, cid, csequence) VALUES (?, ?, ?)";
            try 
            {
              PreparedStatement stmt;
                stmt = getDbcon().con.prepareStatement(query);
             
                stmt.setString(1, (String)slist.get(i));
                stmt.setInt(2, id);
                stmt.setInt(3, i+1);
                System.out.println("zzzzzzzzzzzzzzzzzzzzzzzz"+(String)slist.get(i));
                System.out.println("zzzzzzzzzzzzzzzzzzzzzzzz"+(id+100));
                System.out.println("zzzzzzzzzzzzzzzzzzzzzzzz"+(i+1+100));
                stmt.executeUpdate();	
                stmt.close();
            } catch (Exception ex) 
            {
               
                System.out.println(ex.getMessage());
            }
            }
            getDbcon().disconnect();               
        
    }

   public Vector viewCurseLog (int id){
        //Statement stmt;
        String query;
        ResultSet rs;
        PreparedStatement stmt;
        Vector<CurseLog> cList;
            
        cList = new Vector<CurseLog>();
        Iterator it = cList.iterator();
                
        getDbcon().connect();
        query = "SELECT * FROM CurseLog WHERE cid = ?";
        
        try
        {
            stmt = getDbcon().con.prepareStatement(query);
            stmt.setInt(1, id);
            rs = stmt.executeQuery();	
        
            while (rs.next()) 
            {	
                CurseLog c = new CurseLog();
                c.cid = rs.getInt("cid");
                c.cmessage = rs.getString("cmessage");
                c.csequence = rs.getInt("csequence");
                cList.add(c);
              
             }
            //crset.populate(rs);
            rs.close(); 					
            stmt.close();
            return cList;
 				
        } catch (Exception ex)
        {
            System.out.println(ex.getMessage());	       	
        }
       finally {
            getDbcon().disconnect();
        }
        return null;
     }
    
    public dbConnection getDbcon() {
        return dbcon;
    }

    public void setDbcon(dbConnection dbcon) {
        this.dbcon = dbcon;
    }

}
